// utils/authCheck.js
import { getValueBykey } from '@/indexDB/dbKV'

export async function checkLogin() {
  const userInfo = await getValueBykey("userInfo");
  const token = await getValueBykey("token");
  return !!(userInfo && token);
}

export async function requireLogin(redirectTo = '/login') {
  const isLoggedIn = await checkLogin();
  if (!isLoggedIn) {
    // 可以跳转到登录页
    if (redirectTo) {
      window.location.href = redirectTo;
    }
    return false;
  }
  return true;
}